home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / e / AEPD24.lha / EPD24 / Amiga_E-Programme / FVList / FVList.e < prev    next >
Text File  |  1980-02-01  |  5KB  |  133 lines

  1. /* FVlist: a class for handling linked-list-stuff with that little extra
  2.  
  3. This kind of linked list has a member pointer to the root of the list,
  4. and this root has a pointer to the tail, so that:
  5. -the root can be reached from every node in one single action (speed)
  6. -the tail can be reached from the root, so that adding a node to this
  7. list (which is always handled with it's root-element) is also quite
  8. fast.
  9.  
  10. I hear you saying: 'why no normal double-linked list?', and you're
  11. right, except for speed.
  12. Maybe you don't give a damn, but I think it's rather handy...
  13.  
  14. Oh yes, the Disclaimer:
  15. 'Use it, but don't blame me if it blows up your dog or eats
  16. your socks (no good idea anyway :) or some other thing.'
  17.  
  18. Hope you like it.  If you find any bugs (prey there aren't any),
  19. please let me know immediately.
  20. Also, tell me what you use it for.
  21.  
  22. Frank Verheyen
  23. The RedHaired Barbarian
  24. --- Nudge Nudge. Say no more ---
  25.     (Monty Python)
  26.  
  27. (EMAIL) hi910097@Beta.Ufsia.ac.be
  28.  
  29. Wouter can include this into his next E-release if it's any good.
  30.  
  31. */
  32. /*--------------------------------------------------------------------------*/
  33. OPT MODULE
  34.  
  35. EXPORT OBJECT fvnode                    -> a node
  36.     PRIVATE parent:PTR TO fvnode
  37.     PRIVATE child:PTR TO fvnode
  38.     PRIVATE root:PTR TO fvnode
  39. ENDOBJECT
  40.  
  41. EXPORT OBJECT fvlist OF fvnode            -> the rootnode, the list's handle
  42.     PRIVATE tail:PTR TO fvnode
  43. ENDOBJECT
  44. /*--------------------------------------------------------------------------*/
  45. EXPORT PROC make(dummy) OF fvlist            -> constructor
  46.     self.parent := NIL
  47.     self.child := NIL
  48.     self.root := self
  49.     self.tail := NIL
  50. ENDPROC
  51. /*--------------------------------------------------------------------------*/
  52. EXPORT PROC make(r:PTR TO fvlist) OF fvnode    -> constructor
  53.      DEF n:PTR TO fvnode
  54.  
  55.     IF (n := r.tail)
  56.         n.child := self
  57.         self.parent := n
  58.     ENDIF
  59.     IF r.child=NIL
  60.         r.child := self
  61.         self.parent := r
  62.     ENDIF
  63.     r.tail := self                        -> nodes are added at the tail anyway
  64.     self.root := r
  65.     self.child := NIL
  66. ENDPROC
  67. /*--------------------------------------------------------------------------*/
  68. EXPORT PROC show() OF fvnode IS WriteF('Node:\n\taddress=\h\n\tparent=\h\n\tchild=\h\n\troot=\h\n-------------------\n',self,self.parent,self.child,self.root)
  69. /*--------------------------------------------------------------------------*/
  70. EXPORT PROC show() OF fvlist
  71.     DEF n:PTR TO fvnode
  72.     WriteF('Root:\n\taddress=\h\n\tparent=\h\n\tchild=\h\n\troot=\h\n\ttail=\h\n-------------------\n',self,self.parent,self.child,self.root,self.tail)
  73.     IF (n := self.child)
  74.         WHILE n
  75.             n.show()
  76.             n := n.child
  77.         ENDWHILE
  78.     ELSE
  79.         WriteF('Empty list, no children linked\n-------------------\n')
  80.     ENDIF
  81. ENDPROC
  82. /*--------------------------------------------------------------------------*/
  83. EXPORT PROC giveRoot() OF fvnode IS self.root
  84. /*--------------------------------------------------------------------------*/
  85. EXPORT PROC giveChild() OF fvnode IS self.child
  86. /*--------------------------------------------------------------------------*/
  87. EXPORT PROC giveParent() OF fvnode IS self.parent
  88. /*--------------------------------------------------------------------------*/
  89. EXPORT PROC giveTail() OF fvnode IS self.root::fvlist.tail
  90. /*--------------------------------------------------------------------------*/
  91. EXPORT PROC giveTail() OF fvlist IS self.tail
  92. /*--------------------------------------------------------------------------*/
  93. /* this rather funny construction of ENDing a self is a solution to be able to
  94.  implement the delete() (fvnode cannot have an end() destructor, at least not
  95.  a recursive one).  Think about it :) */
  96.  
  97. EXPORT PROC free() OF fvnode                -> free nodes after and including self
  98.     DEF n:PTR TO fvnode,r:PTR TO fvlist,p:PTR TO fvnode
  99.     IF (n := self.child) THEN n.free()        -> recursively free list of children
  100.  
  101.      p := self.parent
  102.      p.child := NIL                        -> amputation of parent
  103.      r := self.root
  104.     r.tail := p                        -> update root's tail
  105. ->     PrintF('freeing \h\n',self)            -> for debugging purposes
  106.     END self
  107. ENDPROC
  108. /*--------------------------------------------------------------------------*/
  109. EXPORT PROC end() OF fvlist
  110.     DEF n:PTR TO fvnode
  111.     IF (n := self.child)
  112.         n.free()
  113.     ENDIF
  114. ->    PrintF('freeing root \h\n',self)        -> for debugging purposes
  115. ENDPROC
  116. /*--------------------------------------------------------------------------*/
  117. EXPORT PROC delete() OF fvnode
  118.     DEF    p:PTR TO fvnode,
  119.         c:PTR TO fvnode,
  120.         r:PTR TO fvlist
  121.     p := self.parent
  122.     c := self.child
  123.     r := self.root
  124.     IF p THEN p.child := c
  125.     IF c
  126.         c.parent := p
  127.     ELSE
  128.         IF r THEN r.tail := p
  129.     ENDIF
  130.     END self
  131. ENDPROC
  132. /*------------------------------ that's it folks ---------------------------*/
  133.